#include <board.h>
#include <rtthread.h>
#include <drv_gpio.h>
#include "rtdbg.h"
#ifndef RT_USING_NANO
#include <rtdevice.h>
#endif /* RT_USING_NANO */

#define PARAMETER       RT_NULL
#ifndef LED_THREAD_STACK_SIZE
#define LED_THREAD_STACK_SIZE      256
#endif
#define PRIORITY        8             


rt_base_t user_led_pin;
rt_thread_t user_led_thread;

void user_led_entry(void *param)
{
    
    while (1)
    {
        rt_pin_write(user_led_pin, PIN_HIGH);
        rt_thread_mdelay(500);
        rt_pin_write(user_led_pin, PIN_LOW);
        rt_thread_mdelay(500);
        // LOG_D("running led thread.");
    }
    
}

int user_led_run(void)
{
   user_led_pin = rt_pin_get("PC.13");
   if (user_led_pin == RT_NULL)
   {
        LOG_E("user led pin get error");
        return -1;
   }

   rt_pin_mode(user_led_pin, PIN_MODE_OUTPUT);

   user_led_thread = rt_thread_create("led_thread",
                                        user_led_entry,
                                        PARAMETER,
                                        LED_THREAD_STACK_SIZE,
                                        PRIORITY,
                                        20);

    if (user_led_thread == RT_NULL)
    {
        LOG_E("user led thread create error");
        return -1;
    }
    rt_thread_startup(user_led_thread);
    return 0;
}
INIT_APP_EXPORT(user_led_run);